<template>
  <div class="login-container">
    <div class="main-container">
      <div class="main-item">
        <div class="label">账号</div>
        <div class="value">
          <input type="text" v-model="form.username" placeholder="请输入手机号">
        </div>
      </div>
      <div class="main-item">
        <div class="label">密码</div>
        <div class="value">
          <input type="password" v-model="form.userpwd" placeholder="请输入登陆密码">
        </div>
      </div>
    </div>
    <div class="btn-container" @click="submit">
      登陆
    </div>
    <div class="operating-container">
      <div class="left" @click="register">手机号注册</div>
      <div class="right" @click="forgetPwdPhone">忘记原密码？</div>
    </div>
    <div class="other-container">
      <div class="other-item" @click="wechatLogin">
        <img src="~@/assets/icon/wechat.png" alt="">
        <p>微信登陆</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {
        username: null,
        userpwd: null
      }
    }
  },
  methods: {
    register () {
      this.$router.push('/register')
    },
    forgetPwdPhone () {
      this.$router.push('/forgetPwdPhone')
    },
    async submit () {
      if (!this.form.username) {
        this.$toast('请输入账号')
        return
      }
      if (!this.form.userpwd) {
        this.$toast('请输入密码')
        return
      }
      const result = await this.$fetchGet('/home/login/index', this.form)
      if (!result.success) {
        this.$toast(result.msg)
        return
      }
      const userInfo = await this.$fetchGet('/home/member/index')
      if (!userInfo.success) {
        this.$toast(userInfo.msg)
        return
      }
      this.$store.commit('changeUserData', userInfo.data.member)
      this.$store.commit('changeCartList')
      this.$router.push('/my')
    },
    async wechatLogin () {
      // const result = await this.$fetchGet('/home/login/wechat')
      // console.log(result)
      window.location.href = 'https://h5.shujingvip.com:443/auth/?callback=https://h5.shujingvip.com/home/login/wechat'
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  .main-container {
    width: 100vw;
    padding: 0 40px;
    background: #ffffff;
    box-shadow:  0 0 10px #888;
    margin-top: 5vh;
    .main-item {
      display: flex;
      line-height: 100px;
      padding: 0 20px;
      .label {
        font-size: 30px;
        font-weight: bold;
        color: #505050;
        margin-right: 50px;
      }
      .value {
        flex: 1;
        input {
          width: 100%;
          border: none;
          font-size: 30px;
        }
      }
      &:first-child {
        border-bottom: 1PX solid #E3E3E3;
      }
    }
  }
  .btn-container {
    margin-top: 50px;
    width: 80vw;
    margin-left: 10vw;
    text-align: center;
    line-height: 100px;
    background: linear-gradient(to right,#FC8F04,#F71C19);
    border-radius: 50px;
    font-size: 35px;
    font-weight: bold;
    color: #fff;
    letter-spacing: 10px;
  }
  .operating-container {
    display: flex;
    margin-top: 30px;
    width: 90vw;
    margin-left: 5vw;
    &>div {
      flex: 1;
      font-size: 20px;
      font-weight: bold;
    }
    .left {
      color: #626262;
    }
    .right {
      text-align: right;
      color: #3F9FFE;
    }
  }
  .other-container {
    margin-top: 100px;
    text-align: center;
    .other-item {
      display: inline-block;
      img {
        width: 100px;
        margin-bottom: 20px;
      }
      p {
        font-size: 25px;
        color: #626262;
        font-weight: bold;
      }
    }
  }
}
</style>